const initialState = {
  userInfo: {} as IUserInfo,
  profile: {} as IProfile,
};

type ActionType =
  | { type: "user/saveUserInfo"; payload: IUserInfo }
  | { type: "user/saveProfile"; payload: IProfile };

function userReducer(
  state = initialState,
  action: ActionType
): typeof initialState {
  switch (action.type) {
    case "user/saveUserInfo":
      return { ...state, userInfo: action.payload };
    case "user/saveProfile":
      return { ...state, profile: action.payload };
    default:
      return state;
  }
}

export default userReducer;

interface IUserInfo {
  id: string;
  name: string;
  photo: string;
  art_count: number;
  follow_count: number;
  fans_count: number;
  like_count: number;
}

export interface IProfile {
  id: string;
  photo: string;
  name: string;
  mobile: string;
  gender: number;
  birthday: string;
  intro: string;
}
